const {addComment,getComment,deleteCommentById,searchCommentByName}=require("../service/comment_service")
class CommentController{
    async createComment(ctx, next) {
        let data = ctx.request.body
        try {
            await addComment(data)
            ctx.body = {
                status: 200,
                message:"发表成功"
            }
        } catch (error) {
            console.log(error)
        }
    }
    async findComment(ctx, next) {
        let res = await getComment()
        ctx.body=res
    }
    async deleteComment(ctx, next) {
        let {id}=ctx.params
        try {
            await deleteCommentById(id)
            ctx.body = {
                status: 200,
                message:"删除留言成功"
            }
        } catch (error) {
            console.log(error)
        }
    }
    async searchComment(ctx,next) {
        let { username } = ctx.request.body
        let CommentList=await searchCommentByName(username)
        ctx.body = {
            status: 200,
            message: "搜索成功",
            CommentList
        }
    }
}
module.exports=new CommentController()